Ext.user.taskfunc = function(cfg){
	this.cfg = cfg || {};
	if(this.cfg.time){
		this.date = new Date(this.cfg.time).dateFormat('Y-m-d');
	}else{
		this.date = new Date().dateFormat('Y-m-d');
	}
	this.taskstoreWriter = new Ext.data.JsonWriter({
	   encode: false
	}); 
	this.taskproxy = new Ext.data.HttpProxy({
		api: {
			read : Ext.user.baseUrl +'/Task/data/'
		}
	});	
	this.taskdata = new Ext.data.JsonStore({
				storeId: 'taskStore',
				writer:this.taskstoreWriter,
				proxy:this.taskproxy,
				autoLoad: true,
				root:'list',
				totalProperty: 'count',
				paramNames:{start:'page',limit:'limit'},
				baseParams:{'date':this.date},
				fields: ['id','account','status','nickname',{name:'yuyue',type:'int'},{name:'jiuzhen',type:'int'},{name:'zixun',type:'int'},{name:'youxiao',type:'int'},{name:'zongyouxiao',type:'int'}]
	});
	this.bbar = new Ext.PagingToolbar({
            pageSize: Ext.sysconfig.pageSize,
            store: 'taskStore',
            displayInfo: true,
            displayMsg: Ext.sysconfig.pagemsg,
            emptyMsg: Ext.sysconfig.emptyList
        });

	this.taskcolumn = [
		new Ext.grid.RowNumberer(),
		{xtype: 'gridcolumn',header: '帐号',dataIndex: 'account',sortable: true,width: 10,align: 'center'},
		{xtype: 'gridcolumn',header: '姓名',dataIndex: 'nickname',sortable: true,width: 10,align: 'center'},
		{xtype: 'gridcolumn',header: '咨询机会次数',dataIndex: 'zixun',sortable: true,width: 15},
		{xtype: 'gridcolumn',header: '咨询有效次数',dataIndex: 'youxiao',sortable: true,width: 15},
		{xtype: 'gridcolumn',header: '咨询总有效次数',dataIndex: 'zongyouxiao',sortable: true,width: 15},
		{xtype: 'gridcolumn',header: '预约次数',dataIndex: 'yuyue',sortable: true,width: 15},
		{xtype: 'gridcolumn',header: '就诊次数',dataIndex: 'jiuzhen',sortable: true,width: 15},
		{xtype: 'gridcolumn',header: '状态',dataIndex: 'status',sortable: true,width: 15,renderer:Ext.user.method.status},
		{xtype: 'gridcolumn',header: '操作',dataIndex: 'id',sortable: true,width: 15}                
	];
	return new Ext.grid.EditorGridPanel({
                id:'taskeditgrid', 
				bbar:this.bbar,
				store:this.taskdata, 
				height: window.parent.Ext.getCmp('center_101').getHeight()-90, 
				loadMask: true, 
				border:false,
				trackMouseOver:true,
				columnLines:true,
				cm: new Ext.grid.ColumnModel(this.taskcolumn),
				sm: new Ext.grid.RowSelectionModel({ 
					singleSelect: true
				}),
			    viewConfig: {forceFit: true},
				listeners:{
					rowdblclick:function(g, n, e){
						var time = Ext.getCmp('tasksearch').form.getValues().searchdate;
						if(time == ''){
							var date = new Date().dateFormat('Y-m-d');
						}else{
							var date = new Date(time).dateFormat('Y-m-d');
						}
						var aa = new Ext.user.taskWindow({edit:true});
						aa.show();
						Ext.user.method.loaddataForm({
							url:'/Task/data/',
							params:{'where':g.getSelectionModel().getSelected().id,'do':'id',date:date},
							Formid:'taskform',
							method:'POST',
							recorddata:['uid','yuyue','jiuzhen','zixun','youxiao','zongyouxiao']
						});
						Ext.getCmp('taskform').add(new Ext.form.Hidden({name:'uid',value:g.getSelectionModel().getSelected().id,renderTo:'taskformid'}));
						Ext.getCmp('taskform').add(new Ext.form.Hidden({name:'dates',value:date,renderTo:'taskformid'}));
					}
				}
            });
}
Ext.user.taskfunc1 = function(cfg){
	//alert('aa');
	this.cfg = cfg || {};
	if(this.cfg.time){
		this.date = new Date(this.cfg.time).dateFormat('Y-m');
	}else{
		this.date = new Date().dateFormat('Y-m');
	}
	this.taskstoreWriter = new Ext.data.JsonWriter({
	   encode: false
	}); 
	this.taskproxy = new Ext.data.HttpProxy({
		api: {
			read : Ext.user.baseUrl +'/Task/jobdata/'
		}
	});	
	this.taskdata = new Ext.data.JsonStore({
				storeId: 'taskStore',
				writer:this.taskstoreWriter,
				proxy:this.taskproxy,
				autoLoad: true,
				root:'list',
				totalProperty: 'count',
				paramNames:{start:'page',limit:'limit'},
				baseParams:{'date':this.date},
				fields: ['id','account','status','nickname',{name:'jiuzhen',type:'int'}]
	});
	this.bbar = new Ext.PagingToolbar({
            pageSize: Ext.sysconfig.pageSize,
            store: 'taskStore',
            displayInfo: true,
            displayMsg: Ext.sysconfig.pagemsg,
            emptyMsg: Ext.sysconfig.emptyList
        });

	this.taskcolumn = [
		new Ext.grid.RowNumberer(),
		{xtype: 'gridcolumn',header: '帐号',dataIndex: 'account',sortable: true,width: 10,align: 'center'},
		{xtype: 'gridcolumn',header: '姓名',dataIndex: 'nickname',sortable: true,width: 10,align: 'center'},
		{xtype: 'gridcolumn',header: '计划到诊',dataIndex: 'jiuzhen',sortable: true,width: 15},
		{xtype: 'gridcolumn',header: '状态',dataIndex: 'status',sortable: true,width: 15,renderer:Ext.user.method.status},
		{xtype: 'gridcolumn',header: '操作',dataIndex: 'id',sortable: true,width: 15}                
	];
	return new Ext.grid.EditorGridPanel({
                id:'taskeditgrid', 
				bbar:this.bbar,
				store:this.taskdata, 
				height: window.parent.Ext.getCmp('center_101').getHeight()-90, 
				loadMask: true, 
				border:false,
				trackMouseOver:true,
				columnLines:true,
				cm: new Ext.grid.ColumnModel(this.taskcolumn),
				sm: new Ext.grid.RowSelectionModel({ 
					singleSelect: true
				}),
			    viewConfig: {forceFit: true},
				listeners:{
					rowdblclick:function(g, n, e){
						var time = Ext.getCmp('tasksearch').form.getValues().searchdate;
						if(time == ''){
							var date = new Date().dateFormat('Y-m');
						}else{
							var date = new Date(time).dateFormat('Y-m');
						}
						var aa = new Ext.user.taskWindow1({edit:true});
						aa.show();
						Ext.user.method.loaddataForm({
							url:'/Task/jobdata/',
							params:{'where':g.getSelectionModel().getSelected().id,'do':'id',date:date},
							Formid:'taskform',
							method:'POST',
							recorddata:['uid','jiuzhen']
						});
						Ext.getCmp('taskform').add(new Ext.form.Hidden({name:'uid',value:g.getSelectionModel().getSelected().id,renderTo:'taskformid'}));
						Ext.getCmp('taskform').add(new Ext.form.Hidden({name:'dates',value:date,renderTo:'taskformid'}));
					}
				}
            });
}
Ext.user.taskWindow = Ext.extend(Ext.Window, {
    title: '任务统计',
    width: 400,
	id:'taskWindow',
	modal:true,
    autoHeight:true,
    border: false,
	button:function(){
		Ext.apply(this,this.cfg);
		if(typeof this.edit != 'undefined'){
			this.buttons = [{text:'任务设置',handler:function(){
				Ext.user.method.submitForm('taskform','/Task/edit/',{s:function(){
					var date = Ext.getCmp('taskform').form.getValues().dates;
					Ext.getCmp('taskWindow').close();
					Ext.StoreMgr.lookup('taskStore').reload();
					
				},f:function(){
					//alert('添加失败');
				}},'POST');
			}},{text:'重置',handler:function(){
					Ext.getCmp('taskform').form.reset();
			}}];		
		}
	},
    initComponent: function(cfg) {
		this.cfg = cfg || {};
		this.button();
        this.items = [
            {
                xtype: 'form',
                id: 'taskform',
				formId:'taskformid',
                border: false,
                items: [
                    {
                        xtype: 'fieldset',
                        title: '基本信息',
                        style: 'margin:5px;',
                        items: [
							{
                                xtype: 'numberfield',
                                anchor: '50%',
                                fieldLabel: '咨询机会次数',
                                name: 'zixun',
								value:0,
								allowBlank:false
                            },
							{
                                xtype: 'numberfield',
                                anchor: '50%',
                                fieldLabel: '咨询有效次数',
                                name: 'youxiao',
								value:0,
								allowBlank:false
                            },
							{
                                xtype: 'numberfield',
                                anchor: '50%',
                                fieldLabel: '咨询总有效次数',
                                name: 'zongyouxiao',
								value:0,
								allowBlank:false
                            },
							{
                                xtype: 'numberfield',
                                anchor: '50%',
                                fieldLabel: '预约次数',
                                name: 'yuyue',
								value:0,
								allowBlank:false
                            },
							{
                                xtype: 'numberfield',
                                anchor: '50%',
                                fieldLabel: '就诊次数',
                                name: 'jiuzhen',
								value:0,
								allowBlank:false
                            }
                        ]
                    }
                ]
            }
        ];
        Ext.user.taskWindow.superclass.initComponent.call(this);
    }
});
Ext.user.taskWindow1 = Ext.extend(Ext.Window, {
    title: '任务统计',
    width: 400,
	id:'taskWindow1',
	modal:true,
    autoHeight:true,
    border: false,
	button:function(){
		Ext.apply(this,this.cfg);
		if(typeof this.edit != 'undefined'){
			this.buttons = [{text:'任务设置',handler:function(){
				Ext.user.method.submitForm('taskform','/Task/jobedit/',{s:function(){
					var date = Ext.getCmp('taskform').form.getValues().dates;
					Ext.getCmp('taskWindow1').close();
					Ext.StoreMgr.lookup('taskStore').reload();
					
				},f:function(){
					//alert('添加失败');
				}},'POST');
			}},{text:'重置',handler:function(){
					Ext.getCmp('taskform').form.reset();
			}}];		
		}
	},
    initComponent: function(cfg) {
		this.cfg = cfg || {};
		this.button();
        this.items = [
            {
                xtype: 'form',
                id: 'taskform',
				formId:'taskformid',
                border: false,
                items: [
                    {
                        xtype: 'fieldset',
                        title: '基本信息',
                        style: 'margin:5px;',
                        items: [
							{
                                xtype: 'numberfield',
                                anchor: '50%',
                                fieldLabel: '计划到诊数',
                                name: 'jiuzhen',
								value:0,
								allowBlank:false
                            }
                        ]
                    }
                ]
            }
        ];
        Ext.user.taskWindow.superclass.initComponent.call(this);
    }
});

Ext.task = {};
Ext.task.left = [{border:false,xtype:'treepanel',
listeners:{
	click:function(n,e){
		if(n.attributes.id != 'menu'){
			var panel = Ext.getCmp('taskrightpanel');
			panel.removeAll();
			var aa = (Ext.get('taskrightpanel').query('*[class=x-panel-body x-panel-body-noheader x-panel-body-noborder]'))[0].id;
			switch(n.attributes.id){
				case 1:
					panel.add(Ext.task.rightcishu(aa));
				break;
				case 2:
					panel.add(Ext.task.rightmonth(aa));
				break;
			}
		}
	}
},
root: {text:'任务管理',id: 'menu'},loader: {baseParams:{'do':'leftid'},url:Ext.user.baseUrl + '/Task/data/',requestMethod: 'POST'}}];
Ext.task.items = [];
Ext.task.items[0] = {xtype:'panel',columnWidth:0.2,items:Ext.task.left,height:window.parent.Ext.getCmp('center_101').getHeight()-27};
Ext.task.items[1] = {id:'taskrightpanel',border:false,xtype:'panel',columnWidth:0.8,height:window.parent.Ext.getCmp('center_101').getHeight()-27};

Ext.task.rightcishu = function(aa){
	this.tasktabara = [
		{xtype:'panel',columnWidth: 0.08,items:[{xtype:'panel',style:'margin-left:5px;margin-right:5px;line-height:20px;',html:'查询时间:'}]},
		{xtype:'panel',columnWidth: 0.12,items:[{name:'searchdate',xtype:'datefield'}]},
		{xtype:'panel',style:'margin-left:5px;',columnWidth: 0.06,items:[{xtype:'button',text:'查  找',handler:function(){
			var time = Ext.getCmp('tasksearch').form.getValues().searchdate;
			var searchtime = function (m) { return new Date(time).dateFormat('Y-m-d'); };
			var panel = Ext.getCmp('taskpanel');
			panel.removeAll();
			var aa = (Ext.get('taskpanel').query('*[class=x-panel-body x-panel-body-noborder]'))[0].id;
			panel.add(new Ext.user.taskfunc({'time':searchtime(time)}).render(aa));	
		}}]}
];
	this.tasktabar = {frame:true,autoWidth:true,border:false,id:'tasksearch',xtype:'form',title:'',height:40,layout: 'column',items:this.tasktabara}
	return new Ext.Panel({title:'次数',tbar:this.tasktabar,renderTo:aa,id:'taskpanel',autoHeight:true,authoWidth:true,border:false,items:new Ext.user.taskfunc()});
}
Ext.task.rightmonth = function(aa){
	this.tasktabara = [
		{xtype:'panel',columnWidth: 0.08,items:[{xtype:'panel',style:'margin-left:5px;margin-right:5px;line-height:20px;',html:'查询时间:'}]},
		{xtype:'panel',columnWidth: 0.12,items:[{name:'searchdate',xtype:'datefield',format:'Y-m'}]},
		{xtype:'panel',style:'margin-left:5px;',columnWidth: 0.06,items:[{xtype:'button',text:'查  找',handler:function(){
			var time = Ext.getCmp('tasksearch').form.getValues().searchdate;
			var searchtime = function (m) { return new Date(time).dateFormat('Y-m'); };
			var panel = Ext.getCmp('taskpanel');
			panel.removeAll();
			var aa = (Ext.get('taskpanel').query('*[class=x-panel-body x-panel-body-noborder]'))[0].id;
			panel.add(new Ext.user.taskfunc1({'time':searchtime(time)}).render(aa));	
		}}]}
];
	this.tasktabar = {frame:true,autoWidth:true,border:false,id:'tasksearch',xtype:'form',title:'',height:40,layout: 'column',items:this.tasktabara}
	return new Ext.Panel({title:'月任务',tbar:this.tasktabar,renderTo:aa,id:'taskpanel',autoHeight:true,authoWidth:true,border:false,items:new Ext.user.taskfunc1()});
}
Ext.user.taskdatalist = Ext.extend(Ext.Panel, { 
	renderTo:'task_index',
	title:'任务管理',
	layout:'column',
	height:window.parent.Ext.getCmp('center_101').getHeight(),
    initComponent: function() {
		this.items = Ext.task.items,
        Ext.user.taskdatalist.superclass.initComponent.call(this);
    }
});
